home *** CD-ROM | disk | FTP | other *** search
- #include <EPPC.h>
- #include <AppleEvents.h>
- #include <Aliases.h>
- #include <string.h>
- #include <Memory.h>
- #include <TextUtils.h>
- #include <Strings.h>
-
- #include "IsAppRunning.h"
-
- void testNetscape(void);
-
- static AEDesc theAddressDesc;
-
- static Boolean Find_NetScape(void);
-
- static pascal Boolean MyFilter(LocationNamePtr locationName, PortInfoPtr thePortInfo);
- static pascal Boolean MyIdle(EventRecord *theEvent, long *sleepTIme, RgnHandle *mouseRgn);
- static Boolean OpenNetscape(void);
- static OSErr CloseNetscape(void);
- static void ActivateNetScape(void);
-
- static Boolean opened = false;
-
- /**************************************************************************************************
- *
- *
- * PUBLIC FUNCTIONS
- *
- *
- **************************************************************************************************/
-
- Boolean OpenURL(char *url); // go to the page specified by the url
-
- void ShowFile(char *name); // have netscape show the file with the name (may launch helper apps)
-
-
- Boolean OpenURL(char *name)
- {
- AppleEvent theAppleEvent, theReply;
- OSErr err;
-
- if (Find_NetScape() == false)
- return false;
-
-
- err = AECreateAppleEvent ('WWW!','OURL', &theAddressDesc,
- kAutoGenerateReturnID, kAnyTransactionID, &theAppleEvent);
-
-
- err = AEPutParamPtr(&theAppleEvent, keyDirectObject, typeChar, name, strlen(name));
-
- err = AESend(&theAppleEvent, &theReply,
- kAEWaitReply,kAENormalPriority, kNoTimeOut,
- NewAEIdleProc(MyIdle), NewAEFilterProc(MyFilter));
-
- if( err == noErr )
- return true;
- else
- return false;
- }
-
- void ShowFile(char *name)
- {
- AppleEvent theAppleEvent, theReply;
- OSErr err;
- AliasHandle alias = nil;
- FSSpec fss;
- short vRefNum;
- char pstr[256];
-
-
- if (Find_NetScape() == false)
- return;
-
-
- err = AECreateAppleEvent ('WWW!','SHWL', &theAddressDesc,
- kAutoGenerateReturnID, kAnyTransactionID, &theAppleEvent);
-
-
- GetVol(nil, &vRefNum);
- strcpy(pstr, name);
- c2pstr(pstr);
-
- err = FSMakeFSSpec( vRefNum, 0, (StringPtr)pstr, &fss);
- err = NewAlias(nil, &fss, &alias);
-
- err = AEPutParamPtr(&theAppleEvent, keyDirectObject, typeAlias, &alias,
- GetHandleSize((Handle)alias));
-
- err = AESend(&theAppleEvent, &theReply,
- kAEWaitReply,kAENormalPriority, kNoTimeOut,
- NewAEIdleProc(MyIdle), NewAEFilterProc(MyFilter));
- }
-
- /**************************************************************************************************
- *
- *
- * PUBLIC FUNCTIONS
- *
- *
- **************************************************************************************************/
-
- static pascal Boolean MyFilter(LocationNamePtr locationName, PortInfoPtr thePortInfo)
- {
- #pragma unused (locationName, thePortInfo)
- return true;
- }
-
- static pascal Boolean MyIdle(EventRecord *theEvent, long *sleepTIme, RgnHandle *mouseRgn)
- {
- #pragma unused (theEvent, sleepTIme, mouseRgn)
- return false;
- }
-
-
- static Boolean Find_NetScape(void)
- {
- ProcessSerialNumber targetPSN ;
-
- ProcessInfoRec targetPIRec ;
- Str255 targetName ;
- OSErr err = paramErr;
- Boolean retVal = false ;
-
- // if we are running we want the PSN and stuff,
- // otherwise we need to launch it and get the information
-
- if(!IsAppRunning( 'APPL',
- 'MOSS',
- &targetPSN,
- &targetPIRec,
- targetName ) )
- {
- err = LaunchApp( 'MOSS' ) ;
-
- if( err == noErr)
- retVal = true;
- else
- retVal = false;
- } else if (targetPIRec.processSignature == 'MOSS')
- retVal = true;
- else
- retVal = false ;
-
- if( retVal == true ) {
- if( opened == false) { // you only want to create the descriptor once
- DescType sig = 'MOSS';
-
- err = AECreateDesc (typeApplSignature, (Ptr) &sig, sizeof(DescType), &theAddressDesc);
- if (err != noErr) {
- retVal = false;
- } else {
- opened = true;
- retVal = true;
- }
- }
- } else
- retVal = false;
-
- return retVal ;
-
- }
-
- static Boolean OpenNetscape(void)
- {
- OSErr err = noErr;
-
-
- if (!opened) {
- if (Find_NetScape() == false)
- return false;
-
- {
- DescType sig = 'MOSS';
-
- err = AECreateDesc (typeApplSignature, (Ptr) &sig, sizeof(DescType), &theAddressDesc);
- if (err == noErr)
- opened = true;
- else
- return false;
- }
- }
-
- return true;
- }
-
- static OSErr CloseNetscape(void)
- {
- return AEDisposeDesc (&theAddressDesc);
- }
-
- static void ActivateNetScape(void)
- {
- AppleEvent theAppleEvent, theReply;
- OSErr err;
-
- if (Find_NetScape() == false)
- return;
-
- err = AECreateAppleEvent('WWW!','ACTV',&theAddressDesc,
- kAutoGenerateReturnID, kAnyTransactionID,&theAppleEvent);
-
- err = AESend(&theAppleEvent, &theReply, kAEWaitReply,kAENormalPriority, kNoTimeOut, nil, nil);
-
- }